package com.vhuomai.system.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.vhuomai.system.constant.UserRole;
import com.vhuomai.system.entity.BaseSysMerchant;
import com.vhuomai.system.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author harris
 */
@Api(tags = "商户信息")
@RestController
@RequestMapping("/api")
@Scope(role = UserRole.MANAGER)
public class MerchantController {
    
    @Autowired
    private MerchantService merchantService;
    
    @ApiOperation(value = "商户详情")
    @GetMapping(value = "/merchant/detail", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<BaseSysMerchant> detail() {
        return ServiceResult.success(merchantService.find());
    }
    
    @ApiOperation(value = "添加商户")
    @PostMapping(value = "/merchant/detail", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<BaseSysMerchant> addMerchant(@RequestBody BaseSysMerchant merchant) {
        return ServiceResult.success(merchantService.add(merchant));
    }
    
    @ApiOperation(value = "修改商户")
    @PutMapping(value = "/merchant/detail", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> updateMerchant(@RequestBody BaseSysMerchant merchant) {
        merchantService.update(merchant);
        return ServiceResult.SUCCESS;
    }
}
